package LeetCode.interview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Stack;

import LeetCode.interview._104_Maximum_Depth_of_Binary_Tree.TreeNode;
import sun.tools.jar.resources.jar;
import util.LogUtils;

/*
 * 
原题　
		Write a function that takes a string as input and reverse only the vowels of a string.
	
	Example 1:
	Given s = "hello", return "holle".
	
	Example 2:
	Given s = "leetcode", return "leotcede".
	
	Note:
	The vowels does not include the letter "y". 
题目大意
	反转字符串中的元音
解题思路
	头尾双指针
 * @Date 2017-10-09 09：17
 */
public class _345_Reverse_Vowels_of_a_String {
	/**
	 * 法一：使用stack实现 
	 * @param s
	 * @return
	 */
	public String reverseVowels(String s) {
		if (s == null)	return null;
		
		char[] arr = s.toCharArray();
		Stack<Character> stack = new Stack<Character>();
		for (int i = 0; i < s.length(); i ++) {
			Character ch = arr[i];
			if (isVowels(ch)) {
				stack.push(ch);
			} 
		}
		for (int i = 0; i < s.length(); i ++) {
			Character ch = arr[i];
			if (isVowels(ch)) {
				arr[i] = stack.pop();
			}
		}
		return new String(arr);
	}
	public boolean isVowels(char c){
	    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ){
	        return true;
	    }
	    return false;
	}
	public static void main(String[] args) {
		_345_Reverse_Vowels_of_a_String obj = new _345_Reverse_Vowels_of_a_String();

		obj.reverseVowels(null);
	}

}
